package com.lyc.yuki.module.finance.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyc.yuki.common.result.ResponseResult;
import com.lyc.yuki.module.finance.domain.po.FundAccountPO;
import com.lyc.yuki.module.finance.service.FundAccountService;
import com.lyc.yuki.module.system.domain.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: lyc
 * @Date: 2025/7/19 16:33
 */
@RestController
@RequestMapping("/finance/fundAccount")
public class FundAccountController {

    @Autowired
    private FundAccountService fundAccountService;

    @GetMapping("/page")
    public ResponseResult<IPage<FundAccountPO>> page(@RequestParam(defaultValue = "1") Integer current,
                                                     @RequestParam(defaultValue = "10") Integer size) {
        Page<FundAccountPO> page = new Page<>(current, size);
        IPage<FundAccountPO> fundAccountPOIPage = fundAccountService.pageItem(page);
        return ResponseResult.successWithData(fundAccountPOIPage);
    }

    @DeleteMapping("/batchDelete")
    public ResponseResult<Boolean> batchDelete(@RequestBody List<Integer> ids) {
        boolean flag = fundAccountService.removeByIds(ids);
        return ResponseResult.successWithData(flag);
    }

    @PutMapping("/saveOrUpdate")
    public ResponseResult<Boolean> saveOrUpdate(@RequestBody FundAccountPO fundAccountPO) {
        boolean flag = fundAccountService.saveOrUpdate(fundAccountPO);
        return ResponseResult.successWithData(flag);
    }

    @GetMapping("/{name}")
    public ResponseResult<List<FundAccountPO>> getUserListByUserName(@PathVariable String name) {
        List<FundAccountPO> fundAccountPOList =  fundAccountService.getFundAccountListByName(name);
        return ResponseResult.successWithData(fundAccountPOList);
    }
}

